package com.nc.user.controller;


import com.nc.user.model.dto.RoleDto;
import com.nc.user.service.RoleService;
import com.plug.result.RetResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 创建人:    xvzhe
 * 创建时间:
 * 修改时间:
 * 版本:      v1.0
 */
@RestController
@RequestMapping("RoleController")
@Api(tags = "角色接口")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @PostMapping("role")
    @ApiOperation("增加角色")
    public RetResult addRole(@RequestBody RoleDto roleDto) {
        return roleService.save(roleDto);
    }

    @PutMapping("role/{id}")
    @ApiOperation("更新角色")
    public RetResult updateRole(@PathVariable String id, @RequestBody RoleDto roleDto) {
        roleDto.setId(id);
        return roleService.save(roleDto);
    }

    @GetMapping("find/all")
    @ApiOperation("查询全部")
    public RetResult findAll(String name) {
        return roleService.findAll(name);
    }

    @GetMapping("find/permission/{code}")
    @ApiOperation("根据权限code查询角色")
    public RetResult findPerCode(@PathVariable String code) {
        return roleService.findByPermissionsCode(code);
    }

}
